package com.sdry.service.impl.hpf;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.sdry.mapper.hpf.PickApplyDetailMapper;
import com.sdry.model.hpf.PickApplyDetail;
import com.sdry.service.hpf.PickApplyDetailService;

/**
 * @ClassName: PickApplyDetailServiceImpl 
 * @Description:领料申请单详情Service实现
 * @Author hpf
 * @Date 2018年10月9日 下午3:07:10 
 * @version 1.0
 */
@Service
public class PickApplyDetailServiceImpl implements PickApplyDetailService {

	@Resource
	private PickApplyDetailMapper pickApplyDetailMapper;
	
	/**
	 * 条件查询领料申请单详情总数
	 * @param pickApplyDetail 查询条件
	 * @return
	 */
	public Integer countPickApplyDetail(PickApplyDetail pickApplyDetail) {
		// TODO Auto-generated method stub
		return pickApplyDetailMapper.countPickApplyDetail(pickApplyDetail);
	}

	/**
	 * 分页查询领料申请单详情
	 * @param map 查询条件
	 * @return
	 */
	public List<PickApplyDetail> listPagePickApplyDetail(Map<String, Object> map) {
		// TODO Auto-generated method stub
		return pickApplyDetailMapper.listPagePickApplyDetail(map);
	}

	/**
	 * 条件查询所有领料申请单详情
	 * @param PickApplyDetail 查询条件
	 * @return
	 */
	public List<PickApplyDetail> listAllPickApplyDetail(PickApplyDetail pickApplyDetail) {
		// TODO Auto-generated method stub
		return pickApplyDetailMapper.listAllPickApplyDetail(pickApplyDetail);
	}

	/**
	 * 新增领料申请单详情
	 * @param pickApplyDetail 领料申请单详情实体
	 * @return
	 */
	public Integer insertPickApplyDetail(PickApplyDetail pickApplyDetail) {
		// TODO Auto-generated method stub
		return pickApplyDetailMapper.insertPickApplyDetail(pickApplyDetail);
	}

	/**
	 * 修改领料申请单详情
	 * @param pickApplyDetail 领料申请单详情实体
	 * @return
	 */
	public Integer updatePickApplyDetail(PickApplyDetail pickApplyDetail) {
		// TODO Auto-generated method stub
		return pickApplyDetailMapper.updatePickApplyDetail(pickApplyDetail);
	}

	/**
	 * 根据ID删除领料申请单详情
	 * @param pickDetailIDs 领料申请单详情ID拼接字符串（以，分割）
	 * @return
	 */
	@Transactional(rollbackFor={Exception.class})
	public Integer deletePickApplyDetail(String pickDetailIDs) {
		// TODO Auto-generated method stub
		int isSuccess = 0;
		try {
			String[] ids = pickDetailIDs.split(",");
			for (int i = 0; i < ids.length; i++) {
				isSuccess = pickApplyDetailMapper.deletePickApplyDetail(Long.parseLong(ids[i]));
			}
		} catch (Exception e) {
			e.printStackTrace();     
	        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
	        isSuccess = 0;
		}
		return isSuccess;
	}
	
}
